<?php
###############   COPYLEFT GPLv3 LICENSE   ###############
##
## JFX Version 0.2.9
## Website Management Software
## www.jfxcms.com
##
## Copyright 2009 GPLv3 - http://www.opensource.org/licenses/gpl-3.0.html
##
## Anthony Gallon
## oi_antz@hotmail.com
##
## Permission is hereby granted to any person having a copy of this software
## to freely use and modify as required so long as the copyright notices
## and branding remain intact.
##
## Full license details available at http://www.jfxcms.com/license
##
###############   COPYLEFT GPLv3 LICENSE   ###############

$module = get('moduleName');
$method = get('moduleMethod');
$pageId = post('page_id', get('pageId'));
$id = get('blockId');

$moduleObj = JFX_Module::getInstance($module);

// try for block id
$block = JFX_Block::getBlockById($id, $pageId, '', false, true);
$content = '';

if($block){
    // ok it is a block
    $blockid = $id;
    ob_start();
    $moduleObj->$method($block, $pageId);
    $content = ob_get_contents();
    ob_end_clean();

}

$res = new stdClass();

if(is_object($moduleObj)){
    
    if(array_key_exists('tiny_live_textareas', $_SESSION) && strlen($_SESSION['tiny_live_textareas'])>0){
		$js = <<<JS
	tinyMCE.init({
		theme : "advanced",
		mode : "exact",
		elements : "{$_SESSION['tiny_live_textareas']}"
	});

JS;

		$VIEW->addJs($js);
	}


    $js = $VIEW->getJs();
    $dom = phpQuery::newDocumentXhtml($js);
    
    $res->js = (string) pq('script');
    $res->error = JFX::getError();
    $res->success = JFX::getSuccess();
    $res->content = $content;
}else{
    $res->content = 'Invalid method for this module';
    $res->js = '';
}

while(ob_get_level()>0) ob_end_clean();

die(json_encode($res));




